package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class Discounter extends HttpServlet {

	private int schriftgroesse = 24;
	private ServletConfig konfiguration;

	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		this.konfiguration = config;
		try {
			schriftgroesse = Integer.parseInt(config
					.getInitParameter("fontsize"));
		} catch (NumberFormatException nfe) {
		}

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();

		out.println(ServletUtilities.headWithTitle("Discounter - Angebote")
				+ "<body><h1>Aktuelle Angebote</h1>");

		// Alle Parameter
		Enumeration<String> alleParameter = konfiguration
				.getInitParameterNames();
		String parameterName;
		String angebote = "--- ";
		while (alleParameter.hasMoreElements()) {
			parameterName = alleParameter.nextElement();
			if (parameterName.contains("angebot"))
						angebote = angebote + konfiguration.getInitParameter(parameterName) + " --- ";
		}

		out.println("<APPLET CODE = Laufschrift.class WIDTH=400 HEIGHT=400>"
				+ "<PARAM NAME = \"angebot\" VALUE = \"" + angebote + "\">"
				+ "<PARAM NAME = \"fontsize\" VALUE = \"" + schriftgroesse
				+ "\">" + "</APPLET>");

		out.println("</body></html>");
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
